home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevdbit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  20.2 KB  |  711 lines

  1. /* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevdbit.c,v 1.2 2000/09/19 19:00:12 lpd Exp $ */
  20. /* Default device bitmap copying implementation */
  21. #include "gx.h"
  22. #include "gpcheck.h"
  23. #include "gserrors.h"
  24. #include "gsbittab.h"
  25. #include "gsrect.h"
  26. #include "gsropt.h"
  27. #include "gxdcolor.h"
  28. #include "gxdevice.h"
  29. #include "gxdevmem.h"
  30. #include "gdevmem.h"
  31. #undef mdev
  32. #include "gxcpath.h"
  33.  
  34. /* By default, implement tile_rectangle using strip_tile_rectangle. */
  35. int
  36. gx_default_tile_rectangle(gx_device * dev, const gx_tile_bitmap * tile,
  37.    int x, int y, int w, int h, gx_color_index color0, gx_color_index color1,
  38.               int px, int py)
  39. {
  40.     gx_strip_bitmap tiles;
  41.  
  42.     *(gx_tile_bitmap *) & tiles = *tile;
  43.     tiles.shift = tiles.rep_shift = 0;
  44.     return (*dev_proc(dev, strip_tile_rectangle))
  45.     (dev, &tiles, x, y, w, h, color0, color1, px, py);
  46. }
  47.  
  48. /* Implement copy_mono by filling lots of small rectangles. */
  49. /* This is very inefficient, but it works as a default. */
  50. int
  51. gx_default_copy_mono(gx_device * dev, const byte * data,
  52.         int dx, int raster, gx_bitmap_id id, int x, int y, int w, int h,
  53.              gx_color_index zero, gx_color_index one)
  54. {
  55.     bool invert;
  56.     gx_color_index color;
  57.     gx_device_color devc;
  58.  
  59.     fit_copy(dev, data, dx, raster, id, x, y, w, h);
  60.     if (one != gx_no_color_index) {
  61.     invert = false;
  62.     color = one;
  63.     if (zero != gx_no_color_index) {
  64.         int code = (*dev_proc(dev, fill_rectangle))
  65.         (dev, x, y, w, h, zero);
  66.  
  67.         if (code < 0)
  68.         return code;
  69.     }
  70.     } else {
  71.     invert = true;
  72.     color = zero;
  73.     }
  74.     color_set_pure(&devc, color);
  75.     return gx_dc_default_fill_masked
  76.     (&devc, data, dx, raster, id, x, y, w, h, dev, rop3_T, invert);
  77. }
  78.  
  79. /* Implement copy_color by filling lots of small rectangles. */
  80. /* This is very inefficient, but it works as a default. */
  81. int
  82. gx_default_copy_color(gx_device * dev, const byte * data,
  83.               int dx, int raster, gx_bitmap_id id,
  84.               int x, int y, int w, int h)
  85. {
  86.     int depth = dev->color_info.depth;
  87.     byte mask;
  88.  
  89.     dev_proc_fill_rectangle((*fill));
  90.     const byte *row;
  91.     int iy;
  92.  
  93.     if (depth == 1)
  94.     return (*dev_proc(dev, copy_mono)) (dev, data, dx, raster, id,
  95.                         x, y, w, h,
  96.                     (gx_color_index) 0, (gx_color_index) 1);
  97.     fit_copy(dev, data, dx, raster, id, x, y, w, h);
  98.     fill = dev_proc(dev, fill_rectangle);
  99.     mask = (byte) ((1 << depth) - 1);
  100.     for (row = data, iy = 0; iy < h; row += raster, ++iy) {
  101.     int ix;
  102.     gx_color_index c0 = gx_no_color_index;
  103.     const byte *ptr = row + ((dx * depth) >> 3);
  104.     int i0;
  105.  
  106.     for (i0 = ix = 0; ix < w; ++ix) {
  107.         gx_color_index color;
  108.  
  109.         if (depth >= 8) {
  110.         color = *ptr++;
  111.         switch (depth) {
  112.             case 32:
  113.             color = (color << 8) + *ptr++;
  114.             case 24:
  115.             color = (color << 8) + *ptr++;
  116.             case 16:
  117.             color = (color << 8) + *ptr++;
  118.         }
  119.         } else {
  120.         uint dbit = (-(ix + dx + 1) * depth) & 7;
  121.  
  122.         color = (*ptr >> dbit) & mask;
  123.         if (dbit == 0)
  124.             ptr++;
  125.         }
  126.         if (color != c0) {
  127.         if (ix > i0) {
  128.             int code = (*fill)
  129.             (dev, i0 + x, iy + y, ix - i0, 1, c0);
  130.  
  131.             if (code < 0)
  132.             return code;
  133.         }
  134.         c0 = color;
  135.         i0 = ix;
  136.         }
  137.     }
  138.     if (ix > i0) {
  139.         int code = (*fill) (dev, i0 + x, iy + y, ix - i0, 1, c0);
  140.  
  141.         if (code < 0)
  142.         return code;
  143.     }
  144.     }
  145.     return 0;
  146. }
  147.  
  148. int
  149. gx_no_copy_alpha(gx_device * dev, const byte * data, int data_x,
  150.        int raster, gx_bitmap_id id, int x, int y, int width, int height,
  151.          gx_color_index color, int depth)
  152. {
  153.     return_error(gs_error_unknownerror);
  154. }
  155.  
  156. int
  157. gx_default_copy_alpha(gx_device * dev, const byte * data, int data_x,
  158.        int raster, gx_bitmap_id id, int x, int y, int width, int height,
  159.               gx_color_index color, int depth)
  160. {                /* This might be called with depth = 1.... */
  161.     if (depth == 1)
  162.     return (*dev_proc(dev, copy_mono)) (dev, data, data_x, raster, id,
  163.                         x, y, width, height,
  164.                         gx_no_color_index, color);
  165.     /*
  166.      * Simulate alpha by weighted averaging of RGB values.
  167.      * This is very slow, but functionally correct.
  168.      */
  169.     {
  170.     const byte *row;
  171.     gs_memory_t *mem = dev->memory;
  172.     int bpp = dev->color_info.depth;
  173.     uint in_size = gx_device_raster(dev, false);
  174.     byte *lin;
  175.     uint out_size;
  176.     byte *lout;
  177.     int code = 0;
  178.     gx_color_value color_rgb[3];
  179.     int ry;
  180.  
  181.     fit_copy(dev, data, data_x, raster, id, x, y, width, height);
  182.     row = data;
  183.     out_size = bitmap_raster(width * bpp);
  184.     lin = gs_alloc_bytes(mem, in_size, "copy_alpha(lin)");
  185.     lout = gs_alloc_bytes(mem, out_size, "copy_alpha(lout)");
  186.     if (lin == 0 || lout == 0) {
  187.         code = gs_note_error(gs_error_VMerror);
  188.         goto out;
  189.     }
  190.     (*dev_proc(dev, map_color_rgb)) (dev, color, color_rgb);
  191.     for (ry = y; ry < y + height; row += raster, ++ry) {
  192.         byte *line;
  193.         int sx, rx;
  194.  
  195.         DECLARE_LINE_ACCUM_COPY(lout, bpp, x);
  196.  
  197.         code = (*dev_proc(dev, get_bits)) (dev, ry, lin, &line);
  198.         if (code < 0)
  199.         break;
  200.         for (sx = data_x, rx = x; sx < data_x + width; ++sx, ++rx) {
  201.         gx_color_index previous = gx_no_color_index;
  202.         gx_color_index composite;
  203.         int alpha2, alpha;
  204.  
  205.         if (depth == 2)    /* map 0 - 3 to 0 - 15 */
  206.             alpha = ((row[sx >> 2] >> ((3 - (sx & 3)) << 1)) & 3) * 5;
  207.         else
  208.             alpha2 = row[sx >> 1],
  209.             alpha = (sx & 1 ? alpha2 & 0xf : alpha2 >> 4);
  210.           blend:if (alpha == 15) {    /* Just write the new color. */
  211.             composite = color;
  212.         } else {
  213.             if (previous == gx_no_color_index) {    /* Extract the old color. */
  214.             if (bpp < 8) {
  215.                 const uint bit = rx * bpp;
  216.                 const byte *src = line + (bit >> 3);
  217.  
  218.                 previous =
  219.                 (*src >> (8 - (bit + bpp))) &
  220.                 ((1 << bpp) - 1);
  221.             } else {
  222.                 const byte *src = line + (rx * (bpp >> 3));
  223.  
  224.                 previous = 0;
  225.                 switch (bpp >> 3) {
  226.                 case 4:
  227.                     previous += (gx_color_index) * src++ << 24;
  228.                 case 3:
  229.                     previous += (gx_color_index) * src++ << 16;
  230.                 case 2:
  231.                     previous += (gx_color_index) * src++ << 8;
  232.                 case 1:
  233.                     previous += *src++;
  234.                 }
  235.             }
  236.             }
  237.             if (alpha == 0) {    /* Just write the old color. */
  238.             composite = previous;
  239.             } else {    /* Blend RGB values. */
  240.             gx_color_value rgb[3];
  241.  
  242.             (*dev_proc(dev, map_color_rgb)) (dev, previous, rgb);
  243. #if arch_ints_are_short
  244. #  define b_int long
  245. #else
  246. #  define b_int int
  247. #endif
  248. #define make_shade(old, clr, alpha, amax) \
  249.   (old) + (((b_int)(clr) - (b_int)(old)) * (alpha) / (amax))
  250.             rgb[0] = make_shade(rgb[0], color_rgb[0], alpha, 15);
  251.             rgb[1] = make_shade(rgb[1], color_rgb[1], alpha, 15);
  252.             rgb[2] = make_shade(rgb[2], color_rgb[2], alpha, 15);
  253. #undef b_int
  254. #undef make_shade
  255.             composite =
  256.                 (*dev_proc(dev, map_rgb_color)) (dev, rgb[0],
  257.                                  rgb[1], rgb[2]);
  258.             if (composite == gx_no_color_index) {    /* The device can't represent this color. */
  259.                 /* Move the alpha value towards 0 or 1. */
  260.                 if (alpha == 7)    /* move 1/2 towards 1 */
  261.                 ++alpha;
  262.                 alpha = (alpha & 8) | (alpha >> 1);
  263.                 goto blend;
  264.             }
  265.             }
  266.         }
  267.         LINE_ACCUM(composite, bpp);
  268.         }
  269.         LINE_ACCUM_COPY(dev, lout, bpp, x, rx, raster, ry);
  270.     }
  271.       out:gs_free_object(mem, lout, "copy_alpha(lout)");
  272.     gs_free_object(mem, lin, "copy_alpha(lin)");
  273.     return code;
  274.     }
  275. }
  276.  
  277. int
  278. gx_no_copy_rop(gx_device * dev,
  279.          const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
  280.            const gx_color_index * scolors,
  281.          const gx_tile_bitmap * texture, const gx_color_index * tcolors,
  282.            int x, int y, int width, int height,
  283.            int phase_x, int phase_y, gs_logical_operation_t lop)
  284. {
  285.     return_error(gs_error_unknownerror);    /* not implemented */
  286. }
  287.  
  288. int
  289. gx_default_fill_mask(gx_device * orig_dev,
  290.              const byte * data, int dx, int raster, gx_bitmap_id id,
  291.              int x, int y, int w, int h,
  292.              const gx_drawing_color * pdcolor, int depth,
  293.              gs_logical_operation_t lop, const gx_clip_path * pcpath)
  294. {
  295.     gx_device *dev;
  296.     gx_device_clip cdev;
  297.     gx_color_index colors[2];
  298.     gx_strip_bitmap *tile;
  299.  
  300.     if (gx_dc_is_pure(pdcolor)) {
  301.     tile = 0;
  302.     colors[0] = gx_no_color_index;
  303.     colors[1] = gx_dc_pure_color(pdcolor);
  304.     } else if (gx_dc_is_binary_halftone(pdcolor)) {
  305.     tile = gx_dc_binary_tile(pdcolor);
  306.     colors[0] = gx_dc_binary_color0(pdcolor);
  307.     colors[1] = gx_dc_binary_color1(pdcolor);
  308.     } else
  309.     return_error(gs_error_unknownerror);    /* not implemented */
  310.     if (pcpath != 0) {
  311.     gx_make_clip_path_device(&cdev, pcpath);
  312.     cdev.target = orig_dev;
  313.     dev = (gx_device *) & cdev;
  314.     (*dev_proc(dev, open_device)) (dev);
  315.     } else
  316.     dev = orig_dev;
  317.     if (depth > 1) {
  318.     /****** CAN'T DO ROP OR HALFTONE WITH ALPHA ******/
  319.     return (*dev_proc(dev, copy_alpha))
  320.         (dev, data, dx, raster, id, x, y, w, h, colors[1], depth);
  321.     }
  322.     if (lop != lop_default) {
  323.     gx_color_index scolors[2];
  324.  
  325.     scolors[0] = gx_device_white(dev);
  326.     scolors[1] = gx_device_black(dev);
  327.     if (tile == 0)
  328.         colors[0] = colors[1];    /* pure color */
  329.     /*
  330.      * We want to write only where the mask is a 1, so enable source
  331.      * transparency.  We have to include S in the operation,
  332.      * otherwise S_transparent will be ignored.
  333.      */
  334.     return (*dev_proc(dev, strip_copy_rop))
  335.         (dev, data, dx, raster, id, scolors, tile, colors,
  336.          x, y, w, h,
  337.          gx_dc_phase(pdcolor).x, gx_dc_phase(pdcolor).y,
  338.          lop | (rop3_S | lop_S_transparent));
  339.     }
  340.     if (tile == 0) {
  341.     return (*dev_proc(dev, copy_mono))
  342.         (dev, data, dx, raster, id, x, y, w, h,
  343.          gx_no_color_index, colors[1]);
  344.     }
  345.     /*
  346.      * Use the same approach as the default copy_mono (above).  We
  347.      * should really clip to the intersection of the bounding boxes of
  348.      * the device and the clipping path, but it's too much work.
  349.      */
  350.     fit_copy(orig_dev, data, dx, raster, id, x, y, w, h);
  351.     {
  352.     dev_proc_strip_tile_rectangle((*tile_proc)) =
  353.         dev_proc(dev, strip_tile_rectangle);
  354.     const byte *row = data + (dx >> 3);
  355.     int dx_bit = dx & 7;
  356.     int wdx = w + dx_bit;
  357.     int iy;
  358.  
  359.     for (row = data, iy = 0; iy < h; row += raster, iy++) {
  360.         int ix;
  361.  
  362.         for (ix = dx_bit; ix < wdx;) {
  363.         int i0;
  364.         uint b;
  365.         uint len;
  366.         int code;
  367.  
  368.         /* Skip 0-bits. */
  369.         b = row[ix >> 3];
  370.         len = byte_bit_run_length[ix & 7][b ^ 0xff];
  371.         if (len) {
  372.             ix += ((len - 1) & 7) + 1;
  373.             continue;
  374.         }
  375.         /* Scan 1-bits. */
  376.         i0 = ix;
  377.         for (;;) {
  378.             b = row[ix >> 3];
  379.             len = byte_bit_run_length[ix & 7][b];
  380.             if (!len)
  381.             break;
  382.             ix += ((len - 1) & 7) + 1;
  383.             if (ix >= wdx) {
  384.             ix = wdx;
  385.             break;
  386.             }
  387.             if (len < 8)
  388.             break;
  389.         }
  390.         /* Now color the run from i0 to ix. */
  391.         code = (*tile_proc)
  392.             (dev, tile, i0 - dx_bit + x, iy + y, ix - i0, 1,
  393.              colors[0], colors[1],
  394.              gx_dc_phase(pdcolor).x, gx_dc_phase(pdcolor).y);
  395.         if (code < 0)
  396.             return code;
  397. #undef row_bit
  398.         }
  399.     }
  400.     }
  401.     return 0;
  402. }
  403.  
  404. /* Default implementation of strip_tile_rectangle */
  405. int
  406. gx_default_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles,
  407.    int x, int y, int w, int h, gx_color_index color0, gx_color_index color1,
  408.                 int px, int py)
  409. {                /* Fill the rectangle in chunks. */
  410.     int width = tiles->size.x;
  411.     int height = tiles->size.y;
  412.     int raster = tiles->raster;
  413.     int rwidth = tiles->rep_width;
  414.     int rheight = tiles->rep_height;
  415.     int shift = tiles->shift;
  416.     gs_id tile_id = tiles->id;
  417.  
  418.     fit_fill_xy(dev, x, y, w, h);
  419.  
  420. #ifdef DEBUG
  421.     if (gs_debug_c('t')) {
  422.     int ptx, pty;
  423.     const byte *ptp = tiles->data;
  424.  
  425.     dlprintf4("[t]tile %dx%d raster=%d id=%lu;",
  426.           tiles->size.x, tiles->size.y, tiles->raster, tiles->id);
  427.     dlprintf6(" x,y=%d,%d w,h=%d,%d p=%d,%d\n",
  428.           x, y, w, h, px, py);
  429.     dlputs("");
  430.     for (pty = 0; pty < tiles->size.y; pty++) {
  431.         dprintf("   ");
  432.         for (ptx = 0; ptx < tiles->raster; ptx++)
  433.         dprintf1("%3x", *ptp++);
  434.     }
  435.     dputc('\n');
  436.     }
  437. #endif
  438.  
  439.     if (dev_proc(dev, tile_rectangle) != gx_default_tile_rectangle) {
  440.     if (shift == 0) {    /*
  441.                  * Temporarily patch the tile_rectangle procedure in the
  442.                  * device so we don't get into a recursion loop if the
  443.                  * device has a tile_rectangle procedure that conditionally
  444.                  * calls the strip_tile_rectangle procedure.
  445.                  */
  446.         dev_proc_tile_rectangle((*tile_proc)) =
  447.         dev_proc(dev, tile_rectangle);
  448.         int code;
  449.  
  450.         set_dev_proc(dev, tile_rectangle, gx_default_tile_rectangle);
  451.         code = (*tile_proc)
  452.         (dev, (const gx_tile_bitmap *)tiles, x, y, w, h,
  453.          color0, color1, px, py);
  454.         set_dev_proc(dev, tile_rectangle, tile_proc);
  455.         return code;
  456.     }
  457.     /* We should probably optimize this case too, for the benefit */
  458.     /* of window systems, but we don't yet. */
  459.     } {                /*
  460.                  * Note: we can't do the following computations until after
  461.                  * the fit_fill_xy.
  462.                  */
  463.     int xoff =
  464.     (shift == 0 ? px :
  465.      px + (y + py) / rheight * tiles->rep_shift);
  466.     int irx = ((rwidth & (rwidth - 1)) == 0 ?    /* power of 2 */
  467.            (x + xoff) & (rwidth - 1) :
  468.            (x + xoff) % rwidth);
  469.     int ry = ((rheight & (rheight - 1)) == 0 ?    /* power of 2 */
  470.           (y + py) & (rheight - 1) :
  471.           (y + py) % rheight);
  472.     int icw = width - irx;
  473.     int ch = height - ry;
  474.     byte *row = tiles->data + ry * raster;
  475.  
  476.     dev_proc_copy_mono((*proc_mono));
  477.     dev_proc_copy_color((*proc_color));
  478.     int code;
  479.  
  480.     if (color0 == gx_no_color_index && color1 == gx_no_color_index)
  481.         proc_color = dev_proc(dev, copy_color);
  482.     else
  483.         proc_color = 0, proc_mono = dev_proc(dev, copy_mono);
  484.  
  485. #define real_copy_tile(srcx, tx, ty, tw, th, id)\
  486.   code =\
  487.     (proc_color != 0 ?\
  488.      (*proc_color)(dev, row, srcx, raster, id, tx, ty, tw, th) :\
  489.      (*proc_mono)(dev, row, srcx, raster, id, tx, ty, tw, th, color0, color1));\
  490.   if (code < 0) return_error(code);\
  491.   return_if_interrupt()
  492. #ifdef DEBUG
  493. #define copy_tile(srcx, tx, ty, tw, th, tid)\
  494.   if_debug6('t', "   copy id=%lu sx=%d => x=%d y=%d w=%d h=%d\n",\
  495.         tid, srcx, tx, ty, tw, th);\
  496.   real_copy_tile(srcx, tx, ty, tw, th, tid)
  497. #else
  498. #define copy_tile(srcx, tx, ty, tw, th, id)\
  499.   real_copy_tile(srcx, tx, ty, tw, th, id)
  500. #endif
  501.     if (ch >= h) {        /* Shallow operation */
  502.         if (icw >= w) {    /* Just one (partial) tile to transfer. */
  503.         copy_tile(irx, x, y, w, h,
  504.               (w == width && h == height ? tile_id :
  505.                gs_no_bitmap_id));
  506.         } else {
  507.         int ex = x + w;
  508.         int fex = ex - width;
  509.         int cx = x + icw;
  510.         ulong id = (h == height ? tile_id : gs_no_bitmap_id);
  511.  
  512.         copy_tile(irx, x, y, icw, h, gs_no_bitmap_id);
  513.         while (cx <= fex) {
  514.             copy_tile(0, cx, y, width, h, id);
  515.             cx += width;
  516.         }
  517.         if (cx < ex) {
  518.             copy_tile(0, cx, y, ex - cx, h, gs_no_bitmap_id);
  519.         }
  520.         }
  521.     } else if (icw >= w && shift == 0) {
  522.         /* Narrow operation, no shift */
  523.         int ey = y + h;
  524.         int fey = ey - height;
  525.         int cy = y + ch;
  526.         ulong id = (w == width ? tile_id : gs_no_bitmap_id);
  527.  
  528.         copy_tile(irx, x, y, w, ch, (ch == height ? id : gs_no_bitmap_id));
  529.         row = tiles->data;
  530.         do {
  531.         ch = (cy > fey ? ey - cy : height);
  532.         copy_tile(irx, x, cy, w, ch,
  533.               (ch == height ? id : gs_no_bitmap_id));
  534.         }
  535.         while ((cy += ch) < ey);
  536.     } else {
  537.         /* Full operation.  If shift != 0, some scan lines */
  538.         /* may be narrow.  We could test shift == 0 in advance */
  539.         /* and use a slightly faster loop, but right now */
  540.         /* we don't bother. */
  541.         int ex = x + w, ey = y + h;
  542.         int fex = ex - width, fey = ey - height;
  543.         int cx, cy;
  544.  
  545.         for (cy = y;;) {
  546.         ulong id = (ch == height ? tile_id : gs_no_bitmap_id);
  547.  
  548.         if (icw >= w) {
  549.             copy_tile(irx, x, cy, w, ch,
  550.                   (w == width ? id : gs_no_bitmap_id));
  551.         } else {
  552.             copy_tile(irx, x, cy, icw, ch, gs_no_bitmap_id);
  553.             cx = x + icw;
  554.             while (cx <= fex) {
  555.             copy_tile(0, cx, cy, width, ch, id);
  556.             cx += width;
  557.             }
  558.             if (cx < ex) {
  559.             copy_tile(0, cx, cy, ex - cx, ch, gs_no_bitmap_id);
  560.             }
  561.         }
  562.         if ((cy += ch) >= ey)
  563.             break;
  564.         ch = (cy > fey ? ey - cy : height);
  565.         if ((irx += shift) >= rwidth)
  566.             irx -= rwidth;
  567.         icw = width - irx;
  568.         row = tiles->data;
  569.         }
  570.     }
  571. #undef copy_tile
  572. #undef real_copy_tile
  573.     }
  574.     return 0;
  575. }
  576.  
  577. int
  578. gx_no_strip_copy_rop(gx_device * dev,
  579.          const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
  580.              const gx_color_index * scolors,
  581.        const gx_strip_bitmap * textures, const gx_color_index * tcolors,
  582.              int x, int y, int width, int height,
  583.              int phase_x, int phase_y, gs_logical_operation_t lop)
  584. {
  585.     return_error(gs_error_unknownerror);    /* not implemented */
  586. }
  587.  
  588. /* ---------------- Unaligned copy operations ---------------- */
  589.  
  590. /*
  591.  * Implementing unaligned operations in terms of the standard aligned
  592.  * operations requires adjusting the bitmap origin and/or the raster to be
  593.  * aligned.  Adjusting the origin is simple; adjusting the raster requires
  594.  * doing the operation one scan line at a time.
  595.  */
  596. int
  597. gx_copy_mono_unaligned(gx_device * dev, const byte * data,
  598.         int dx, int raster, gx_bitmap_id id, int x, int y, int w, int h,
  599.                gx_color_index zero, gx_color_index one)
  600. {
  601.     dev_proc_copy_mono((*copy_mono)) = dev_proc(dev, copy_mono);
  602.     uint offset = ALIGNMENT_MOD(data, align_bitmap_mod);
  603.     int step = raster & (align_bitmap_mod - 1);
  604.  
  605.     /* Adjust the origin. */
  606.     data -= offset;
  607.     dx += offset << 3;
  608.  
  609.     /* Adjust the raster. */
  610.     if (!step) {        /* No adjustment needed. */
  611.     return (*copy_mono) (dev, data, dx, raster, id,
  612.                  x, y, w, h, zero, one);
  613.     }
  614.     /* Do the transfer one scan line at a time. */
  615.     {
  616.     const byte *p = data;
  617.     int d = dx;
  618.     int code = 0;
  619.     int i;
  620.  
  621.     for (i = 0; i < h && code >= 0;
  622.          ++i, p += raster - step, d += step << 3
  623.         )
  624.         code = (*copy_mono) (dev, p, d, raster, gx_no_bitmap_id,
  625.                  x, y + i, w, 1, zero, one);
  626.     return code;
  627.     }
  628. }
  629.  
  630. int
  631. gx_copy_color_unaligned(gx_device * dev, const byte * data,
  632.             int data_x, int raster, gx_bitmap_id id,
  633.             int x, int y, int width, int height)
  634. {
  635.     dev_proc_copy_color((*copy_color)) = dev_proc(dev, copy_color);
  636.     int depth = dev->color_info.depth;
  637.     uint offset = (uint) (data - (const byte *)0) & (align_bitmap_mod - 1);
  638.     int step = raster & (align_bitmap_mod - 1);
  639.  
  640.     /*
  641.      * Adjust the origin.
  642.      * We have to do something very special for 24-bit data,
  643.      * because that is the only depth that doesn't divide
  644.      * align_bitmap_mod exactly.  In particular, we need to find
  645.      * M*B + R == 0 mod 3, where M is align_bitmap_mod, R is the
  646.      * offset value just calculated, and B is an integer unknown;
  647.      * the new value of offset will be M*B + R.
  648.      */
  649.     if (depth == 24)
  650.     offset += (offset % 3) *
  651.         (align_bitmap_mod * (3 - (align_bitmap_mod % 3)));
  652.     data -= offset;
  653.     data_x += (offset << 3) / depth;
  654.  
  655.     /* Adjust the raster. */
  656.     if (!step) {        /* No adjustment needed. */
  657.     return (*copy_color) (dev, data, data_x, raster, id,
  658.                   x, y, width, height);
  659.     }
  660.     /* Do the transfer one scan line at a time. */
  661.     {
  662.     const byte *p = data;
  663.     int d = data_x;
  664.     int dstep = (step << 3) / depth;
  665.     int code = 0;
  666.     int i;
  667.  
  668.     for (i = 0; i < height && code >= 0;
  669.          ++i, p += raster - step, d += dstep
  670.         )
  671.         code = (*copy_color) (dev, p, d, raster, gx_no_bitmap_id,
  672.                   x, y + i, width, 1);
  673.     return code;
  674.     }
  675. }
  676.  
  677. int
  678. gx_copy_alpha_unaligned(gx_device * dev, const byte * data, int data_x,
  679.        int raster, gx_bitmap_id id, int x, int y, int width, int height,
  680.             gx_color_index color, int depth)
  681. {
  682.     dev_proc_copy_alpha((*copy_alpha)) = dev_proc(dev, copy_alpha);
  683.     uint offset = (uint) (data - (const byte *)0) & (align_bitmap_mod - 1);
  684.     int step = raster & (align_bitmap_mod - 1);
  685.  
  686.     /* Adjust the origin. */
  687.     data -= offset;
  688.     data_x += (offset << 3) / depth;
  689.  
  690.     /* Adjust the raster. */
  691.     if (!step) {        /* No adjustment needed. */
  692.     return (*copy_alpha) (dev, data, data_x, raster, id,
  693.                   x, y, width, height, color, depth);
  694.     }
  695.     /* Do the transfer one scan line at a time. */
  696.     {
  697.     const byte *p = data;
  698.     int d = data_x;
  699.     int dstep = (step << 3) / depth;
  700.     int code = 0;
  701.     int i;
  702.  
  703.     for (i = 0; i < height && code >= 0;
  704.          ++i, p += raster - step, d += dstep
  705.         )
  706.         code = (*copy_alpha) (dev, p, d, raster, gx_no_bitmap_id,
  707.                   x, y + i, width, 1, color, depth);
  708.     return code;
  709.     }
  710. }
  711.